package com.xxx.borrow.ui.loan.activity;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.TextView;

import com.xxx.borrow.ConfigClass;
import com.xxx.borrow.R;
import com.xxx.borrow.base.activity.BaseTitleActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class BorrowActivity extends BaseTitleActivity {

    public static void actionStart(Activity activity) {
        Intent intent = new Intent(activity, BorrowActivity.class);
        activity.startActivity(intent);
    }

    @BindView(R.id.coin_date)
    TextView mDate;
    @BindView(R.id.coin_type)
    TextView mCoinType;
    @BindView(R.id.enter_money)
    EditText mMoney;
    private String day;
    private String type;

    @Override
    protected String initTitle() {
        return "立即借款";
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_borrow;
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.borrow, R.id.re_day, R.id.re_type_coin})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.borrow://立即借款
                break;
            case R.id.re_day://分期天数
                showDayPopMenu();
                break;
            case R.id.re_type_coin://币种
                showCoinPopMenu();
                break;
        }
    }

    private void showDayPopMenu() {
        PopupMenu popupMenu = new PopupMenu(this, mDate);
        popupMenu.inflate(R.menu.day_menu);
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    case R.id.action_1:
                        day = ConfigClass.DAY_ONE;
                        break;
                    case R.id.action_2:
                        day = ConfigClass.DAY_TWO;
                        break;
                    case R.id.action_3:
                        day = ConfigClass.DAY_THREE;
                        break;
                    case R.id.action_4:
                        day = ConfigClass.DAY_FOUR;
                        break;
                    default:
                        day = ConfigClass.DAY_FOUR;
                        break;
                }
                mDate.setText(menuItem.getTitle());
                return true;
            }
        });
        popupMenu.show();
    }

    private void showCoinPopMenu() {
        PopupMenu popupMenu = new PopupMenu(this, mCoinType);
        popupMenu.inflate(R.menu.day_menu);
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                switch (menuItem.getItemId()) {
                    case R.id.action_1:
                        type = ConfigClass.COIN_TYPE_USDT;
                        break;
                    case R.id.action_2:
                        type = ConfigClass.COIN_TYPE_AKB;
                        break;
                    default:
                        type = ConfigClass.COIN_TYPE_USDT;
                        break;
                }
                mCoinType.setText(menuItem.getTitle());
                return true;
            }
        });
        popupMenu.show();
    }
}
